]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
loginDialog: Store items in map
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 8 Jul 2025 19:26:27 +0000 (21:26 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Fri, 1 Aug 2025 14:29:25 +0000 (16:29 +0200)
Using the dedicated standard type is a bit cleaner and more optimized
than using "raw" objects as hashes.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3799>
(cherry picked from commit 765c4b622b9168057304a2cc491c5ba6a41f7439)

js/gdm/loginDialog.js

index 15ba43a351e666c5eeb04903ffbf5500091c02b2..05fc52330bb34afe3f5553e800fe91a4ec8bf072 100644 (file)
@@ -182,7 +182,7 @@ const UserList = GObject.registerClass({
         });
 
         this.child = this._box;
-        this._items = {};
+        this._items = new Map();
     }
 
     vfunc_key_focus_in() {
@@ -191,7 +191,7 @@ const UserList = GObject.registerClass({
     }
 
     _moveFocusToItems() {
-        let hasItems = Object.keys(this._items).length > 0;
+        const hasItems = this._items.size > 0;
 
         if (!hasItems)
             return;
@@ -219,10 +219,8 @@ const UserList = GObject.registerClass({
         else
             this._box.remove_style_pseudo_class('expanded');
 
-        for (let userName in this._items) {
-            let item = this._items[userName];
+        for (const item of this._items.values())
             item.sync_hover();
-        }
     }
 
     scrollToItem(item) {
@@ -248,7 +246,7 @@ const UserList = GObject.registerClass({
     }
 
     getItemFromUserName(userName) {
-        let item = this._items[userName];
+        const item = this._items.get(userName);
 
         if (!item)
             return null;
@@ -257,7 +255,7 @@ const UserList = GObject.registerClass({
     }
 
     containsUser(user) {
-        return this._items[user.get_user_name()] != null;
+        return this._items.has(user.get_user_name());
     }
 
     addUser(user) {
@@ -280,7 +278,7 @@ const UserList = GObject.registerClass({
         let item = new UserListItem(user);
         this._box.add_child(item);
 
-        this._items[userName] = item;
+        this._items.set(userName, item);
 
         item.connect('activate', this._onItemActivated.bind(this));
 
@@ -301,17 +299,17 @@ const UserList = GObject.registerClass({
         if (!userName)
             return;
 
-        let item = this._items[userName];
+        const item = this._items.get(userName);
 
         if (!item)
             return;
 
         item.destroy();
-        delete this._items[userName];
+        this._items.delete(userName);
     }
 
     numItems() {
-        return Object.keys(this._items).length;
+        return this._items.size;
     }
 });
 
@@ -351,7 +349,7 @@ const SessionMenuButton = GObject.registerClass({
 
         this._button.connect('clicked', () => this._menu.toggle());
 
-        this._items = {};
+        this._items = new Map();
         this._activeSessionId = null;
         this._populate();
     }
@@ -364,12 +362,11 @@ const SessionMenuButton = GObject.registerClass({
     }
 
     _updateOrnament() {
-        let itemIds = Object.keys(this._items);
-        for (let i = 0; i < itemIds.length; i++) {
-            if (itemIds[i] === this._activeSessionId)
-                this._items[itemIds[i]].setOrnament(PopupMenu.Ornament.DOT);
+        for (const itemId of this._items.keys()) {
+            if (itemId === this._activeSessionId)
+                this._items.get(itemId).setOrnament(PopupMenu.Ornament.DOT);
             else
-                this._items[itemIds[i]].setOrnament(PopupMenu.Ornament.NO_DOT);
+                this._items.get(itemId).setOrnament(PopupMenu.Ornament.NO_DOT);
         }
     }
 
@@ -400,7 +397,7 @@ const SessionMenuButton = GObject.registerClass({
             let id = ids[i];
             let item = new PopupMenu.PopupMenuItem(sessionName);
             this._menu.addMenuItem(item);
-            this._items[id] = item;
+            this._items.set(id, item);
 
             item.connect('activate', () => {
                 this.setActiveSession(id);